<template>
	<view>
		<view class="functionItem" @click="gotoSystemSetting">
			<view class="left">
				<image class="icon" src="@/static/image/icon_permission_camera.png" mode=""></image>
				相机权限
			</view>
			<view class="right">
				<text v-if="cameraAuthorized=='authorized'">已开启</text>
				<text v-else>去设置</text>
				<image class="image" src="@/static/image/icon_more.png" mode=""></image>
			</view>
		</view>
		<view class="functionItem" @click="gotoSystemSetting">
			<view class="left">
				<image class="icon" src="@/static/image/icon_permission_album.png" mode=""></image>
				相册/存储权限
			</view>
			<view class="right">
				<text v-if="albumAuthorized=='authorized'">已开启</text>
				<text v-else>去设置</text>
				<image class="image" src="@/static/image/icon_more.png" mode=""></image>
			</view>
		</view>
		<view class="functionItem" @click="gotoSystemSetting">
			<view class="left">
				<image class="icon" src="@/static/image/icon_permission_position.png" mode=""></image>
				位置信息权限
			</view>
			<view class="right">
				<text v-if="locationAuthorized=='authorized'">已开启</text>
				<text v-else>去设置</text>
				<image class="image" src="@/static/image/icon_more.png" mode=""></image>
			</view>
		</view>
		<view class="functionItem" @click="gotoSystemSetting">
			<view class="left">
				<image class="icon" src="@/static/image/icon_permission_mic.png" mode=""></image>
				麦克风权限
			</view>
			<view class="right">
				<text v-if="microphoneAuthorized=='authorized'">已开启</text>
				<text v-else>去设置</text>
				<image class="image" src="@/static/image/icon_more.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	const api = require("@/static/js/api.js")
	const utils = require("@/static/js/utils.js")
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex';
	let that = null
	import Config from "@/config.js"; // 系统参数

	// #ifdef APP-PLUS
	var plugin = uni.requireNativePlugin('Vnidev-DyPlugin-Core')
	const dyclientId = Config.tiktokClientKeyApp;
	// #endif
	export default {
		data() {
			return {
				albumAuthorized: false,
				cameraAuthorized: false,
				locationAuthorized: false,
				microphoneAuthorized: false,
			};
		},

		computed: {
			...mapState({
				hasLogin: state => state.userInfo.hasLogin,
				isAuthPhone: state => state.userInfo.isAuthPhone,
				isAuthUserInfo: state => state.userInfo.isAuthUserInfo,
				isSeller: state => state.userInfo.isSeller,
				sellerObj: state => state.userInfo.sellerObj,
				buyerObj: state => state.userInfo.buyerObj,
				shopInfo: state => state.userInfo.shopInfo,
			}),
		},

		onLoad(options) {
			that = this;
			
		},
		onShow() {
			this.getAllAuthorized()
		},
		methods: {
			...mapMutations(['setUserInfo', 'setLoginStatus', 'setUserId', "setOrigin"]),
			gotoSystemSetting() {
				let that = this
				uni.openAppAuthorizeSetting({
					success(res) {
						console.log(res)
					}
				})
			},
			getAlbumAuthorized() {
				// #ifdef APP-PLUS
				plugin.hasPhotoPerm({}, data => {
					console.log("getAlbumAuthorized", data)
					if (data.finished && data.write_photo && data.read_photo) {
						this.albumAuthorized = "authorized"
					} else {
						this.albumAuthorized = ""
					}
				});
				// #endif

			},
			getAllAuthorized(){
				// #ifdef APP-PLUS
				const appAuthorizeSetting = uni.getAppAuthorizeSetting()
				this.cameraAuthorized = appAuthorizeSetting.cameraAuthorized
				this.locationAuthorized = appAuthorizeSetting.locationAuthorized
				this.microphoneAuthorized = appAuthorizeSetting.microphoneAuthorized
				
				this.getAlbumAuthorized()
				// console.log(appAuthorizeSetting.albumAuthorized)
				// console.log(appAuthorizeSetting.bluetoothAuthorized)
				// console.log(appAuthorizeSetting.cameraAuthorized)
				// console.log(appAuthorizeSetting.locationAuthorized)
				// console.log(appAuthorizeSetting.locationReducedAccuracy)
				// console.log(appAuthorizeSetting.microphoneAuthorized)
				// console.log(appAuthorizeSetting.notificationAlertAuthorized)
				// console.log(appAuthorizeSetting.notificationAuthorized)
				// console.log(appAuthorizeSetting.notificationBadgeAuthorized)
				// console.log(appAuthorizeSetting.notificationSoundAuthorized)
				// console.log(appAuthorizeSetting.phoneCalendarAuthorized)
				// #endif
			}
		}
	}
</script>

<style>
	page {
		background-color: #f8f8f8;
	}
</style>

<style lang="scss">
	.functionItem {
		width: 750rpx;
		height: 100rpx;
		background-color: #ffffff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 1px;

		.left {
			font-size: 30rpx;
			color: #333333;
			margin-left: 40rpx;
			display: flex;
			align-items: center;

			.icon {
				width: 40rpx;
				height: 40rpx;
				// margin-left: 30rpx;
				margin-right: 30rpx;
			}
		}

		.right {
			display: flex;
			align-items: center;
			font-size: 30rpx;
			color: #999999;
			margin-right: 40rpx;

			.image {
				width: 16rpx;
				height: 22rpx;
				margin-left: 33rpx;
			}
		}
	}
</style>